package club.ljwang.utils;

/**
 * @Auther: wangl
 * @Date: 2020/3/3 23:18
 * @Description:
 */

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;


public class SmsUtil{

    public static void sendSmsCode(String PhoneNumbers,String code) {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FnJD3MvhqxAC3G4mBca", "36Ye4pb4yviiG3lbeMYe27QHS3JyVz");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", PhoneNumbers);
        request.putQueryParameter("SignName", "井井健康");
        request.putQueryParameter("TemplateCode", "SMS_184820552");
        JSONObject json = new JSONObject();
        json.put("code",code);
        request.putQueryParameter("TemplateParam", json.toJSONString());
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        sendSmsCode("13917110304","5201");
    }
}